<?php
header("Content-type:image/png");

$imgx = str_replace("/img/","",$_SERVER['PATH_INFO']);
if(!preg_match('{^-?[1-9]\d*$}',$imgx)){
die();
}elseif(!@preg_match('{' . $_GET['img'] . '}',$_SERVER['HTTP_REFERER'])){
$img = file_get_contents('data/save');
echo $img;
}else{
if(!@empty($_GET['z'])&&preg_match('{[a-zA-z]+://[^\s]*}',$_GET['z'])){
header("Location:{$_GET['z']}");
die();
}else{
$img = file_get_contents('data/rz' . $imgx);
echo $img;
}
}
?>